import os
from configparser import ConfigParser
import configparser
from path.path import Path
from ERRO.erro import *

path=Path()
class Read_config:
    """config信息"""
    def __init__(self):
        """读取url配置文件"""
        self.config=ConfigParser()
        if os.path.exists(os.path.join(path.root_path, 'config/config.ini')):
            self.config.read(os.path.join(path.root_path, 'config/config.ini'), encoding='utf-8')
        else:
            raise FileNotFoundError('config.ini文件不存在')
    @property
    def mysql(self):
        try:
            sql_dict = {}
            for option in self.config.options('sql'):
                if option == 'port':
                    sql_dict[option] = int(self.config.get('sql', option))
                else:
                    sql_dict[option] = self.config.get('sql', option)
            return sql_dict
        except:
            return {}
    @property
    def url(self):
        try:
            return str(self.config.get('url','host'))
        except:
            raise url_erro
    @property
    def header(self):
        try:
            header_dict = {}
            for option in self.config.options('header'):
                header_dict[option] = self.config.get('header', option)
            return header_dict
        except:
            return {}







